<section class="content no-padding">
	<div class="row">
		<div class="box">
			<div class="box-body">
				<div class="col-lg-9 col-md-12 conLeft clearfix" id="person_info_div">
				   	<div class="col-xs-12 col-md-6 col-lg-4">
						<div class="form-group">
				        	<label class="text-muted">姓名/工号:</label>
				        	<span id="openDialog_name"></span>
				    	</div>
					</div>
				   	<div class="col-xs-12 col-md-6 col-lg-4">
						<div class="form-group">
				        	<label class="text-muted">性别:</label>
				        	<span id="openDialog_personnel_sex"></span>
				    	</div>
					</div>
				   	<div class="col-xs-12 col-md-6 col-lg-4">
						<div class="form-group">
				        	<label class="text-muted">所属部门:</label>
				        	<span id="openDialog_dept_name"></span>
				    	</div>
					</div>
					<div class="col-xs-12 col-md-6 col-lg-4">
						<div class="form-group">
				        	<label class="text-muted">是否热门歌手展示:</label>
				        	<select class="form-control " id="openDialog_hotSinger" name="openDialog_hotSinger" onchange="changOpenDialogHotSinger(this.options[this.options.selectedIndex].value)">
			                  <option value="0">否</option>
			                  <option value="1">是</option>
		                	</select>
				    	</div>
					</div>
					<div class="col-xs-12 col-md-6 col-lg-4">
						<div class="form-group" id="openDialog_showOder">
				        	<label class="text-muted">展示排序:</label>
				        	<input type="text" class="form-control" id="openDialog_hotSingerOrder"/>
				    	</div>
					</div>
					<div class="col-xs-12 col-md-12 col-lg-12">
						<div class="form-group" id="openDialog_showOder">
				        	<label class="text-muted">个人照片:</label>
				        	<img id="openDialog_person_img" style="width:400px;height:260px;" src="">
		     				<input type="button" onclick="shangchuan()" value="上传" class="btn btn-primary" id="addBu"></input> 
			    			<input type="button" onclick="deleteLifeImg()" value="删除" class="btn btn-default" id="deleteBu"></input>
				    	</div>
					</div>					
				</div>
				<div class="col-lg-3 col-md-12 conRight" id="head_img_div">
					<img id="openDialog_head_img" style="width:128px;height:128px;"src="">
					<input type="button" onclick="shangchuanHead()" value="上传" class="btn btn-primary" id="addBu"></input> 
			    	<input type="button" onclick="deleteHeadImg()" value="删除" class="btn btn-default" id="deleteBu"></input>
				</div>
			</div>
		</div>
	</div>
</section>
<script type="text/javascript">
var personInfo = "";
var dialog_a;
var defaultImg = global_param.context_name+"/static/img/defaultImg/defaultSquareImg.png";
var defaultImg_cover = global_param.context_name+"/static/img/defaultImg/defaultLongImg.png";

$(function() {
	getPersonInfo();
});

function getPersonInfo(){
    $.ajax({
        type: "POST",
        url: globalUtil.getTimestampUrl("/person/search.do"),
        data: {personnel_id : personId},
        async: false,
        dataType: 'json',
        success: function(result) {
        	 personInfo = result.rows[0];
        	$("#openDialog_name").html(personInfo.personnel_name);
        	$("#openDialog_personnel_sex").html(personInfo.personnel_sex);
        	
        	$("#openDialog_dept_name").html(personInfo.dept_name);
        	if(personInfo.hotSinger == 1){
        		$("#openDialog_hotSinger").val("1");
 	       		$("#openDialog_hotSingerOrder").val(personInfo.hotSingerOrder);
        	}else{
        		$("#openDialog_hotSinger").val("0");
        		$("#openDialog_hotSingerOrder").attr("readonly",true);
        	}
        	
        	if(!personInfo.myHeadPhoto || personInfo.myHeadPhoto == ""){
        		$('#openDialog_head_img').attr('src',global_param.context_name+defaultImg);
        	}else{
        		$('#openDialog_head_img').attr('src',global_param.context_name+personInfo.myHeadPhoto);
        	}
        	
        	if(!personInfo.myCoverPhoto || personInfo.myCoverPhoto == ""){
        		$('#openDialog_person_img').attr('src',global_param.context_name+defaultImg_cover);
        	}else{
        		$('#openDialog_person_img').attr('src',global_param.context_name+personInfo.myCoverPhoto);
        	}
        	
        }
    });
}

function updatePersoninfos(callback){
	
	let hotSinger = $("#openDialog_hotSinger").val();
	let hotSingerOrder = $("#openDialog_hotSingerOrder").val();
	let personImgPath = $("#openDialog_person_img").attr("src");
	let headImgPath = $("#openDialog_head_img").attr("src");
	
	if(headImgPath == defaultImg){
		
		headImgPath = "";
	}
	
	if(personImgPath == defaultImg_cover){
		
		personImgPath = "";
	}
	
	if(hotSinger == 0){
		hotSingerOrder = "";
	}else if(hotSingerOrder == ""){
		hotSingerOrder = 0;
	}
    $.ajax({
        type: "POST",
        url: globalUtil.getTimestampUrl("/person/update.do"),
        data: {personnel_id : personId,personnel_shortCode : personInfo.personnel_shortCode,
        	hotSinger : hotSinger,hotSingerOrder : hotSingerOrder,
        	myHeadPhoto : headImgPath.replace(global_param.context_name,""),myCoverPhoto : personImgPath.replace(global_param.context_name,"")},
        async: false,
        dataType: 'json',
        success: function(result) {
        	if(result.result == "OK"){
        		toastr.success("保存成功");
        		callback&&callback();
        	}else{
        		toastr.success("保存失败");
        	}
        }
    });
}

function changOpenDialogHotSinger(val){
	if(val == 0){
		$("#openDialog_hotSingerOrder").attr("readonly",true);
	}else if(val == 1){
		$("#openDialog_hotSingerOrder").attr("readonly",false);
	}
}

function shangchuanHead(){
	   BootstrapDialog.show({
		title: '上传头像',
		size:BootstrapDialog.SIZE_MIDDLE,
	    message: $('<div style="min-height: 450px;"></div>').load(global_param.context_name+'/static/html/personManage/addHeadImage.html'),
	    buttons: [{
	        label: '保存',
	        cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	        action: function(dialog) {
	        		dialog_a = dialog;
	        		addImgs();
	    	}
	    }, {
	        label: '关闭',
	        cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	        action: function(dialog) {
	            dialog.close();
	        }
	    }]
	});
}


function shangchuan(){
	   BootstrapDialog.show({
		title: '上传个人照片',
		size:BootstrapDialog.SIZE_MIDDLE,
	    message: $('<div style="min-height: 450px;"></div>').load(global_param.context_name+'/static/html/personManage/addLifeImage.html'),
	    buttons: [{
	        label: '保存',
	        cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	        action: function(dialog) {
	        		dialog_a = dialog;
	        		addImgs();
	    	}
	    }, {
	        label: '关闭',
	        cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	        action: function(dialog) {
	            dialog.close();
	        }
	    }]
	});
}

//删除图片
function deleteHeadImg(){
	//删除当前页面图片
	if($('#openDialog_head_img').attr('src')==defaultImg){
		return;
	}
		//修改时删除
		$('#openDialog_head_img').attr('src',defaultImg);
	    toastr.success("操作成功");
}


function deleteLifeImg(){
	//删除当前页面图片
	if($('#openDialog_person_img').attr('src')==defaultImg_cover){
		return;
	}
	//修改时删除
	$('#openDialog_person_img').attr('src', defaultImg_cover);
    toastr.success("操作成功");
}
</script>
